```
c++
#include<isostream>
#include<stdio.h>
#include<string.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<stdlib.h>
#include<unistd.h>
#include<errno.h>
#include<list>
#include<fcntl.h>
#include<sys/mman.h>
#include<sstream>
using namespace std;
class websever
{
  public:
    webserver();
    ~webserver();
    void InirSocket();
    void StartService();
    void *serviceThread(int fd);
   private:
    void ResponseFILE(int ClientSocket, char* filename, int filesize);
    void ResponseHTTPheader(int ClientSocket, char* filetype, int filesize));
    int GetFileSize(char* filename);
    int HandleMsg(int sockt_fd, char*Msg);
    
   private:
    int m_ClientSocket;
    int m_SeverSocket;
    int m_portNum;
    int m_Buffsize;
    int m_Maxlink;
    string m_strMsg;
    list<int> m_listclient;
    char m_buf[1024];
    
};
webServer::webServer()
{
  m_ClientSockt=0;
  m_ServerSockt=0;
  m_portNUm=8080;
  m_Buffsize=1024;
  m_MaxLink=100;
  memset(m_buf, 0,sizeof(m_buf));
}
~webServer::webServer()
{
}

void webServer::InitSocket()
{
  m_ServerSocket = socket(AF_INET,SOCK_STREAM,0);
  if(m_ServerSocket<0)
  {
    cout<<"ERROR CONECTION....."<<endl;
    exit(1);
  }
  struct sockaddr_in sever_addr;
  server_addr.sin_family=AF_INET;
  //server_addr.sin_addr.s_addr=htons(INADDR_ANY);
  server_addr.sin_addr.s_addr=inet_addr("10.1.81.43");
  server_addr.sin_port=htons(m_PortNum);
  
  if(bind(m_ServerSocket, (struct sockaddr*)&sever_addr,sizeof(server_addr))<0)
  {
    cout<<"ERROR BILDING......"<<endl;
    exit(1);
  }
  
  if(listen(m_ServerSocket, m_MaxLink)<0)
  {
    cout<<"ERROR LISTENING......"<<endl;
    exit(1);
  }
 }
 int webServer::GetFileSize(char filename)
 {
    FILE* fp=fopen(filename,"r");
    if(!fp)
    retrun -1;
    fseek(fp, 0L, SEEK_END);
    int size =ftell(fp);
    fclose(fp);
    return size;
 }
void webSever::ResponsHTTPHeader(int ClientSocket,cahr *filetype,int filesize)
{
    char Buffer[1024];
    sprintf(Buffer,"HTTP /1.1 200 OK\r\n");
    sprintf(Buffer,"%sServer: webchat\r\n",Buffer);
    sprintf(Buffer,"%sContent-length:%d\r\n",Buffer,filesize);
    sprintf(Buffer,"%sContent-type:%s;charset=UTF-8\r\n\r\n",Buffer, filetype);
    send(ClientSocket, Buffer, strlen(Buffer), 0);
}
void webServer::ResponseFILE(intb ClientSocket, char*filename, int filesize)
{
  char fileBUffer[filesize];
  FILE*fp =fopen(filename,"r++");
  fread(fileBuffer, 1,filesize,fd);
  send(ClientSocket, fileBuffer,filesize,0);
}
void webServer::HandleMsg(int sock_fd,cahr*Msg)
{
  string strMsg=Msg;
  int filesize=0;

  if(strMsg.find("GET / HTTP")!=-1||strMsg.find(".html")!=-1)
  {
    char *filePath="/home/cui_can/code/webchat.html";
    filesize = GetFileSize(filepath);
    ResponseHTTPHeader(socket_fd, "text/hrml", filesize);
    ResponseFile(socket_fd, filepath, filesize);
    return 0;
  }
  else if(strMsg.find(".js")!=-1)
  {
    char *filePath="/home/cui_can/code/jquery-3.3.1.js";
    filesize = GetFileSize(filepath);
    ResponseHTTPHeader(socket_fd, "application/javascript", filesize);
    ResponseFile(socket_fd, filepath, filesize);
    return 0;
  } 
  else if(strMsg.find("SenMsg")!=-1)
  {
    string MsgBody = "";
    MsgBody = strMsg.substr(strMsg.find("\r\n\r\n")+4, strMsg.length()).data();
    Msgbody.append("\r");
    char* PMSG= (cahr*)MsgBody.c_str();
    m_strMsg.append(MsgBody);
    ResponseHTTPHeader(sockt_fd,"application/x-wwww=form-urlencoded", strlen(PMSG));
    send(sockt_fd,PMSG,strlen(PMSG),0);
    return 0;
  }
  else if(strMsg.find("RecvMsg")!=-1)
  {
    char *PMSG = (char*)m_strMsg.data();
    ResponsHTTPHeader(sockt_fd,"application/x-wwww=form-urlencoded",strle(PMSG));
    send(sockt_fd,PMSG,strlen(PMSG),0);
    return 0
  }
  else
  {
  }
  return -1;
}

void*sock_tread_proc(void*arg)
{
  pthread_detach(pthread_selsf());
  webServer*ptr = (webServer*)srg;
  int sockt_fd =*(int*)arg;
  ptr->ServiceThread(sockt_fd);
  return ((viod*)0);
}
void webServer::ServiceThread(int sockt_fd)
{
  while(1)
  {
    int size;
    memset(m_buf, 0, sizeof(m_buf));
    size = recv(socket_fd,m_buf, szieof(m_buf),0);
    if(size<=0)
    {
      pthread_exit(NULL);
      break;
    }
    if(HandleMsg(socket_fd, m_buf)==-1)
    {
      cout<<"msg error!"<<endl;
    }
  }
  close(sockt_fd);
  return ((void*)0);
}

void webServer::StarService()
{
  InitSocket();
  while(1)
  {
    struct sockaddr_in fromaddr;
    socklen_t size =size(fromaddr);
    m_ClientSocket = accept(m_ServerSocket,(struct socktaddr*)&fromaddr,&size);
    cout<<"IP:"<<inet_ntoa(fromaddr.sin_addr)<<" portnum: "<<ntohs(fromaddr.sin_port)<<endl;
    if(m_ClientSockt<0)
    {
    cout<<"ERROR ACCEPTING"<<endl;
    exit(1);
  }
  pthread_t ThreadID;

  if(pthread_create(&ThreadID, NULL, sock_thread_proc,&m_ClientSocket))
  {
    prror("pthread_create() error");
  }
 close(m_ServerSocket);
}

int main()
{
  webServer webserver;
  webserver.SatrService();
  return 0;
}








```
